import java.util.Stack;

class Solution {
    public int evalRPN(String[] tokens) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < tokens.length; i++) {
            int val1 = 0;
            int val2 = 0;
            if(tokens[i].equals("+")  ||tokens[i].equals("-") || tokens[i].equals("*") || tokens[i].equals("/")){
                val2 = stack.pop();
                val1 = stack.pop();
                switch (tokens[i]){
                    case "+" :
                        stack.push(val1 + val2);
                        break;
                    case "-" :stack.push(val1 - val2);
                        break;
                    case "*" :stack.push(val1 * val2);
                        break;
                    case "/" :stack.push(val1 / val2);
                        break;
                }
            }else{
                stack.push(Integer.parseInt(tokens[i]));
            }
        }
        return stack.pop();
    }
}